package ru.spb.osll.myfit.server.parser;

import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
import ru.spb.osll.myfit.server.Converter;

import static org.junit.Assert.assertTrue;

public class PageElementParserFactoryTest {

  private PageElementParserFactory parserFactory;
  private Converter converter;
  @Before
  public void setUp() {
    converter = EasyMock.createMock(Converter.class);
    parserFactory = new PageElementParserFactory(converter);
  }

  
  @Test
  public void testFindPathParser(){
    String pathLine = "!path tra-ta-ta";
    IPageElementParser parser = parserFactory.getParser(pathLine);
    assertTrue(parser instanceof PathElementParser);
  }
  
  @Test
  public void testFindTableParser(){
    String tableLine = "| Header|";
    IPageElementParser parser = parserFactory.getParser(tableLine);
    assertTrue(parser instanceof TableElementParser); 
  }
  
  @Test
  public void testFindIncludeParser(){
    String includeLine = "!include .include";
    IPageElementParser parser = parserFactory.getParser(includeLine);
    assertTrue(parser instanceof IncludeElementParser);
  }

  @Test
  public void testFindContentParser() {
    String contentLine = "!contents -R2";
    IPageElementParser parser = parserFactory.getParser(contentLine);
    assertTrue(parser instanceof ContentElementParser);
  }
  
  @Test
  public void testFindWikiParser(){
    String wikiText = "text ant [[link]]";
    IPageElementParser parser = parserFactory.getParser(wikiText);
    assertTrue(parser instanceof WikiElementParser);
  }
  
  @Test
  public void testFindDefaultParser(){
    String wrongLine = "!pah tra-ta-ta";
    IPageElementParser parser = parserFactory.getParser(wrongLine);
    assertTrue(parser.equals(parserFactory.getDefaultParser()));
  }
  
}
